'''
https://leetcode.cn/problems/remove-interval
'''
import bisect
from typing import List


class Solution:
    def removeInterval(self, intervals: List[List[int]], toBeRemoved: List[int]) -> List[List[int]]:
        remove_start, remove_end = toBeRemoved
        output = []

        for start, end in intervals:
            # 如果没有重叠，则按原样将间隔添加到列表中。
            if start > remove_end or end < remove_start:
                output.append([start, end])
            else:
                # 需要保留左区间吗？
                if start < remove_start:
                    output.append([start, remove_start])
                # 需要保留右区间吗？
                if end > remove_end:
                    output.append([remove_end, end])

        return output

